package com.xxx.buffer;

/**
 * @version v1.0
 * @Description
 * @Author admin
 * @date 2021/7/19  14:05
 * @Copyright
 */
public class StringBufferDome01 {
    public static void main(String[] args) {
        /*
         * StringBuffer:字符串缓冲区，底层数据结构是字符数组
         * 1.线程安全
         * 2.长度和内容可变
         * 3.可以存储任意类型的数据，但最终都转成字符串
         *
         * 1.增，删，改，查
         *
         * */


        //add();
        //delete();
        // uptate();
        //query();

    }

    private static void query() {
        StringBuffer buffer = new StringBuffer();
        buffer.append("abc").append(100).append("def");
        System.out.println(buffer.indexOf("a"));
    }

    private static void uptate() {
        StringBuffer buffer = new StringBuffer();
        buffer.append("abc").append(100).append("def");
        buffer.replace(2, 4, "A");
        System.out.println(buffer);
        buffer.setCharAt(2, 'B');
        System.out.println(buffer);
    }

    private static void delete() {
        StringBuffer buffer = new StringBuffer();
        buffer.append("abc").append(100).append("def");
        System.out.println(buffer);
        buffer.deleteCharAt(2);
        System.out.println(buffer);
        buffer.delete(2, 4);
        System.out.println(buffer);
    }

    private static void add() {
        String s1 = "abc";
        String s2 = s1.concat("d");
        //System.out.println(s1 == s2);

        StringBuffer buffer = new StringBuffer();//初始化数组的长度是16
        StringBuffer buffer1 = buffer.append("abc");
        // System.out.println(buffer1 == buffer);

        buffer.append(100).append(true).insert(1, "A");
        System.out.println(buffer);
    }
}
